
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servidor;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrador
 */
public class Servidor extends UnicastRemoteObject implements ServidorInterface {

    public String nome = "";
//    public String 

    public Servidor() throws RemoteException {
        super();
    }

    public String executaComando(String comando) throws RemoteException {
        String saida = "";
        try {
            Runtime run = Runtime.getRuntime();
            run.exec(comando);
            saida = "ok";
        } catch (Exception e) {
            saida = "not OK";
        }
        return saida;
    }

    public void conectar() {
        try {
            Registry registry = LocateRegistry.createRegistry(1099);
            registry.bind(nome, this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String args[]) throws Exception {
        try {
            Servidor servidor = new Servidor();
            File file = new File(System.getProperty("user.dir") + "/conf.ini");
            try {
                BufferedReader in = new BufferedReader(new FileReader(file));
                String str;
                while ((str = in.readLine()) != null) {
                    servidor.nome = str;
                }
                in.close();
            } catch (IOException e) {
                JOptionPane.showMessageDialog(null,e.toString());
            }
            servidor.conectar();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null,e.toString());
        }
    }
}



